package com.mostromas.ess.project.controller;

import com.mostromas.ess.entities.UserProjectAccount;
import com.mostromas.ess.project.req.UserProjectAccountREQ;
import com.mostromas.ess.project.service.IUserProjectAccountService;
import com.mostromas.ess.util.base.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@Api(value = "软件用户账户信息管理接口", description = "提供用户交互信息的管理")
@RestController
@RequestMapping("/user")
public class UserProjectAccountController {

    @Autowired
    private IUserProjectAccountService userProjectAccountService;

    @ApiOperation("根据用户名和软件ID查询账号列表")
    @PostMapping("/search")
    public Result search(@RequestBody UserProjectAccountREQ req){

        return userProjectAccountService.queryList(req);
    }

    @ApiOperation("新增用户信息接口")
    @PostMapping
    public Result save(@RequestBody UserProjectAccount account){

        return userProjectAccountService.saveOrUpdateAccount(account);
    }

    @ApiOperation("查询軟件賬戶详情接口")
    @PostMapping("/view")
    public Result view(@RequestBody UserProjectAccountREQ req){
        return userProjectAccountService.getInfoByName(req);
    }
    @ApiOperation("查询軟件賬戶详情接口")
    @PostMapping("/viewByName")
    public Result viewByName(@RequestBody UserProjectAccountREQ req){
        return userProjectAccountService.getInfoByAccountName(req);
    }
    @ApiOperation("删除軟件賬戶详情接口")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable("id") String id){
        userProjectAccountService.removeById(id);
        return Result.ok();
    }
}
